package javaExer.草稿;

/**
 * @author 徐州城
 * @version 1.0
 * 练习线程相关概念
 */
public class 线程 {
    public static void main(String[] args) {
        Dog dog = new Dog();
        dog.start();
        System.out.println("主线程....");
    }
}

class Dog extends Thread{

    @Override
    public void run() {
        int i = 0;
        synchronized (this) { //线程同步，保证锁不被争抢
            while (true) {
                i++;
                try {
                    Thread.sleep(500);
                    System.out.println("小狗汪汪汪~~" + Thread.currentThread().getName());
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

                if (i == 15)
                    break;
            }
        }
    }

}
